<template>
    <!--添加工作经历-->
    <div style="background-color: rgb(245, 245, 245);">
        <headers></headers>
        <div class="title">
            <div class="auto">首页 > 认证考试 > 个人账户信息 > 工作经历</div>
        </div>
        <div class="padding250">
            <div class="auto">
                <div class="content">
                    <p class="titleName">工作经历</p>
                    <div class="formWrapper" style="width: 100%">
                        <Form :label-width="86" label-position="left" class="formMin">
                            <FormItem label="公司名称" style="width: 30%;">
                                <Input v-model="workData.companyName" size="large" placeholder="请输入公司名称"/>
                            </FormItem>
                            <FormItem label="职位名称" style="width: 30%;">
                                <Select v-model="workData.position" placeholder="请选择职位" size="large">
                                    <Option :value="item.name" v-for="item in posts">{{item.name}}</Option>
                                </Select>
                            </FormItem>
                            <FormItem label="业态" style="width: 30%;">
                                <Select v-model="workData.operationType" placeholder="请选择业态" size="large">
                                    <Option :value="item.name" v-for="item in commercials">{{item.name}}</Option>
                                </Select>
                            </FormItem>
                            <FormItem label="工作年限" style="width: 30%;">
                                <Select v-model="workData.workingLife" placeholder="请选择工作年限" size="large">
                                    <Option :value="item.enumName" v-for="item in workingYears">{{item.enumName}}</Option>
                                </Select>
                            </FormItem>
                            <FormItem label="工作描述" class="jobdesc">
                                <i-input type="textarea" v-model="workData.workTask" :autosize="{minRows: 6,maxRows: 5}" placeholder="赶快添加工作描述吧~"></i-input>
                            </FormItem>
                            <FormItem label="" style="width:700px;">
                                <p class="tipwords">注：请填写真实工作经历，我们平台会对你提交的资料做背景调查，如虚假将加入企业黑名单。</p>
                            </FormItem>
                        </Form>
                        <Button type="primary" class="save" v-on:click="addWork()">保存并返回</Button>
                        <Button type="primary" class="save" v-on:click="goBack" style="margin-left: 20px;width: 100px;background-color: #2d8cf0;border-color: #2d8cf0;">返回</Button>
                    </div>

                </div>
            </div>
        </div>
        <footers></footers>
    </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
    .padding250 .auto {
        background-color: #fff;
        margin-top: 30px;
        text-align: left;

        .content {
            padding: 40px;

            .titleName {
                font-size: 20px;
                color: #000;
                margin-bottom: 40px;
            }

        }
    }

    .title {
        font-size: 14px;
        color: #fff;
        height: 60px;
        line-height: 60px;
        background-color: #2F261E;
        text-align: left;
    }

    .jobdesc {
        height: 136px;
        width: 700px;
        margin-bottom: 10px;
    }


    .save {
        background-color: #B2936B;
        color: #fff;
        height: 50px;
        width: 200px;
        font-size: 16px;
        margin-left: 80px;
    }

    .formWrapper {
        width: 330px;

        .tipwords {
            font-size: 14px;
            color: #666;
        }
    }


</style>
<script type="text/ecmascript-6">
    import {getUserWork, addWork} from "../../../http"
    import headers from '../../template/header'
    import footers from '../../template/footer'

    export default {
        name: 'addJob',
        props: {},
        data() {
            return {
                showOrder: 'kaoshi',
                posts: [],//职位名称
                commercials: [],//业态
                workingYears: [],//工作年限
                workData: {
                    companyName: '',
                    operationType: '',//业态
                    position: '',//职位名称
                    workingLife: '',
                    workTask: '',
                    workLifeleaval: ''
                },
            };
        },
        methods: {
            goBack() {
                window.history.back();
            },
            getUserWork() {
                getUserWork().then(res => {
                    console.info(res.data)
                    this.posts = res.data.posts
                    this.commercials = res.data.commercials
                    this.workingYears = res.data.workingYears
                })
            },
            addWork() {
                let that = this
                if (!this.workData.companyName) {
                    this.$Notice.warning({
                        title: "新增工作经历提醒",
                        desc: "请输入公司名称",
                        duration: 3,
                    });
                    return
                }
                if (!this.workData.operationType) {
                    this.$Notice.warning({
                        title: "新增工作经历提醒",
                        desc: "请选择业态",
                        duration: 3,
                    });
                    return
                }
                if (!this.workData.position) {
                    this.$Notice.warning({
                        title: "新增工作经历提醒",
                        desc: "请选择职位",
                        duration: 3,
                    });
                    return
                }
                if (!this.workData.workingLife) {
                    this.$Notice.warning({
                        title: "新增工作经历提醒",
                        desc: "请选择工作年限",
                        duration: 3,
                    });
                    return
                }
                if (!this.workData.workTask) {
                    this.$Notice.warning({
                        title: "新增工作经历提醒",
                        desc: "请填写工作描述",
                        duration: 3,
                    });
                    return
                }
                this.workingYears.forEach(function (element) {
                    if (that.workData.workingLife == element.enumName) {
                        that.workData.workLifeleaval = element.sortOrder
                    }
                });
                addWork(this.workData).then(res => {
                    if (res.code == 200) {
                        this.$Notice.success({
                            title: '新增工作经历提醒',
                            desc: '添加工作经历成功',
                            duration: 3,
                        });
                        this.$router.push({
                            name: 'jobjingli'
                        })
                    }
                })
            },
        },
        created() {
            this.getUserWork()
        },
        components: {
            headers,
            footers
        }
    }
</script>
